package org.cvcsc.weproject.controller.dto;

import java.util.List;
import java.util.stream.Collectors;

import org.cvcsc.weproject.domain.AttendDetailStatus;
import org.cvcsc.weproject.domain.Attendance;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "考勤信息响应对象，包含详细的学生考勤信息")
public class ResponseDtoAttendanceWithDetails extends ResponseDtoAttendance {

    public List<Detail> getDetails() {
        return details;
    }

    public void setDetails(List<Detail> details) {
        this.details = details;
    }

    @Schema(description = "学生考勤详细信息列表")
    private List<Detail> details;

    public ResponseDtoAttendanceWithDetails(Attendance attendance) {
        super(attendance);
        this.details = attendance.getDetails().stream()
                .map(detail -> new Detail(detail.getId(), detail.getStudent().getId(),detail.getStudent().getStudentNameAndNumber().getNumber(),
                        detail.getStudent().getStudentNameAndNumber().getName(), detail.getStatus()))
                .collect(Collectors.toList());
    }

    // 内部类 Detail
    @Schema(description = "学生考勤详细信息")
    public static class Detail {
        @Schema(description = "明细ID", example = "123")
        private final Long id;
        @Schema(description = "学生ID", example = "123")
        private final Long studentId;
        @Schema(description = "学生姓名", example = "张三")
        private final String studentName;
        @Schema(description = "学生学号", example = "2301020034")
        private final String studentNumber;
        @Schema(description = "考勤状态", example = "PRESENT")
        private final String status;

        public Detail(Long id,Long studentId, String studentNumber, String studentName, AttendDetailStatus status) {
            this.id=id;
            this.studentId = studentId;
            this.studentNumber = studentNumber;
            this.studentName = studentName;
            this.status = status.toString();
        }

        // 可选：提供 getter 方法以便外部访问
        public Long getStudentId() {
            return studentId;
        }

        public String getStudentName() {
            return studentName;
        }

        public String getStatus() {
            return status;
        }

        public String getStudentNumber() {
            return studentNumber;
        }


    }
}